package com.iflytek.service.impl;

import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.iflytek.bean.Admin;
import com.iflytek.bean.Goods;
import com.iflytek.bean.GoodsExample;
import com.iflytek.bean.StockInOrder;
import com.iflytek.mapper.GoodsMapper;
import com.iflytek.mapper.StockInOrderMapper;
import com.iflytek.service.StockInOrderService;
import com.iflytek.vo.StockInOrderVO;

@Service
public class StockInOrderServiceImpl implements StockInOrderService{

	@Autowired
	private StockInOrderMapper stockInOrderMapper;
	@Autowired
	private GoodsMapper goodMapper;
	

	@Override
	@Transactional
	public void insertSelective(StockInOrder stockInOrder) {
		Subject subject = SecurityUtils.getSubject();
		Admin admin = (Admin)subject.getPrincipal();
		stockInOrder.setAgent(admin.getName());
		System.out.println(admin.getName());
		stockInOrderMapper.insertSelective(stockInOrder);
////		Goods good = goodMapper.selectByPrimaryKey(stockInOrder.getGoodsId());
////		good.setGoodsNum(good.getGoodsNum()+ stockInOrder.getGoodsNum());
//		goodMapper.updateByPrimaryKeySelective(good);
		
	}

	@Override
	public void deleteByPrimaryKey(Integer orderId) {
		stockInOrderMapper.deleteByPrimaryKey(orderId);
	}

	@Override
	public void updateByPrimaryKeySelective(StockInOrder stockInOrder) {
		Subject subject = SecurityUtils.getSubject();
		Admin admin = (Admin)subject.getPrincipal();
		stockInOrder.setAgent(admin.getName());
		stockInOrderMapper.updateByPrimaryKeySelective(stockInOrder);
	}

	@Override
	public List<StockInOrderVO> selectByExample() {
		
		return stockInOrderMapper.showAll();
	}

	@Override
	public void insertIsApprove(Integer orderId) {
		
		stockInOrderMapper.insertIsApprove(orderId);
	}
	
	
	

}
